home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / os2 / bbs102d.zip / bbsstat.cmd < prev    next >
OS/2 REXX Batch file  |  1996-12-12  |  9KB  |  288 lines

  1. /* The stand alone "bbs statistics" generator */
  2.  
  3.  
  4. /*---- load the rexxlib library */
  5. foo=rxfuncquery('rexxlibregister')
  6. if foo=1 then do
  7.  call rxfuncadd 'rexxlibregister','rexxlib', 'rexxlibregister'
  8.  call rexxlibregister
  9. end
  10. /* Load up advanced REXX functions */
  11. foo=rxfuncquery('sysloadfuncs')
  12. if foo=1 then do
  13.   call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  14.   call SysLoadFuncs
  15. end
  16.  
  17. ansion=checkansi()
  18. if ansion=1 then do
  19.   aesc='1B'x
  20.   cy_ye=aesc||'[37;46;m'
  21.   normal=aesc||'[0;m'
  22.   bold=aesc||'[1;m'
  23.   re_wh=aesc||'[31;47;m'
  24.   reverse=aesc||'[7;m'
  25. end
  26. else do
  27.   cy_ye="" ; normal="" ; bold="" ;re_wh="" ; 
  28.   reverse=""
  29. end  /* Do */
  30.  
  31.  d1=date('b')
  32.  t1=time('m')/(24*60)
  33.  nowtime=d1+t1
  34.  
  35.  
  36. cls
  37. call lineout, bold cy_ye
  38. CALL LINEOUT," This is the statistics generator for the BBS add-on for SRE-Filter. "
  39. call lineout, normal bold "It must be run from the BBS USERLOG_DIR directory " normal
  40. say " "
  41.  
  42. /* First, see how many .in files. */
  43.  
  44. aa=sysfiletree('*.in','infiles','FT')
  45.  
  46. nth=0
  47. say " Reading user information.... "
  48. do mm=1 to infiles.0
  49.    aline=infiles.mm
  50.    parse var aline date size attrib fname
  51.    vlist=get_user_header(fname)
  52.    
  53. /* check variables  */
  54.    if wordpos('STATUS',vlist)=0 then do
  55.         say " ERROR. STATUS: entry missing from: " fname
  56.         iterate
  57.    end
  58.    if wordpos("USER",vlist)=0 then do
  59.         say " ERROR. USER: entry missing from: " fname
  60.         iterate
  61.    end
  62.    parse var user_header.!status downf upf downb upb lasttime
  63.    if  datatype(downf)<>'NUM' | datatype(upf)<>'NUM' | ,
  64.      datatype(downb)<>'NUM' | datatype(upb)<>'NUM' | ,
  65.      datatype(lasttime)<>'NUM' then do
  66.          say "ERROR. Bad STATUS: entry "
  67.    end  /* Do */
  68.  
  69.    parse var user_header.!user user .
  70.  
  71.    nth=nth+1
  72.    entries.nth.!user=user
  73.    entries.nth.!upf=upf ; entries.nth.!downf=downf
  74.    entries.nth.!upb=upb ; entries.nth.!downb=downb
  75.  
  76.    tf=downf/max(1,upf)
  77.    tb=downb/max(1,upb)
  78.    entries.nth.!ratiob=tb
  79.    entries.nth.!ratiof=tf
  80.    entries.nth.!time=lasttime
  81.  
  82. end
  83. say " # of user log files (user.IN files): " infiles.0
  84. say " # of useable log files: " nth
  85.  
  86. /* how sort by upf downf upb downb ratiof ratiob */
  87. totdownb=0; totdownf=0; totupf=0; totupb=0;
  88. do mm=1 to nth
  89.    totdownf=totdownf+entries.mm.!downf
  90.    totdownb=totdownb+entries.mm.!downb
  91.    totupf=totupf+entries.mm.!upf
  92.    totupb=totupb+entries.mm.!upb
  93.    adownf.mm=left(entries.mm.!downf,15)||entries.mm.!user
  94.    aupf.mm=left(entries.mm.!upf,15)||entries.mm.!user
  95.    adownb.mm=left(entries.mm.!downb,15)||entries.mm.!user
  96.    aupb.mm=left(entries.mm.!upb,15)||entries.mm.!user
  97.    aratiof.mm=left(entries.mm.!ratiof,15)||entries.mm.!user
  98.    aratiob.mm=left(entries.mm.!ratiob,15)||entries.mm.!user
  99.    atime.mm=left(entries.mm.!time,15)||entries.mm.!user
  100. end
  101.  
  102. ok=arraysort(adownf,1,,1,15,'D','N')
  103. ok=arraysort(aupf,1,,1,15,'D','N')
  104. ok=arraysort(adownb,1,,1,15,'D','N')
  105. ok=arraysort(aupb,1,,1,15,'D','N')
  106. ok=arraysort(aratiof,1,,1,15,'D','N')
  107. ok=arraysort(aratiob,1,,1,15,'D','N')
  108. ok=arraysort(atime,1,,1,15,'D','N')
  109.  
  110. n2:
  111. call charout ,  reverse ' Display the top n entries:  n  (enter=10)  ? ' normal
  112. pull topn
  113. if topn=""  then topn=10
  114. topn=min(topn,nth)
  115.  
  116. call charout ,  reverse ' Display the number of users in the last d days: d (enter=7)  ? ' normal
  117. pull ddays
  118. if ddays="m"  then ddays=7
  119.  
  120.  
  121.  
  122. getname: call charout, " Filename to write the output report to:"
  123. parse pull outname
  124. outname=dosfname(outname)
  125. hub=stream(outname,'c','query exists')
  126. if hub<>' ' then do
  127.     call charout, hub " exists. Enter Y to overwrite: "
  128.     pull anans
  129.     if upper(anans)='Y' then do
  130.       say " deleting old copy of " hub
  131.         ww=sysfiledelete(hub)
  132.     end  /* Do */
  133.     else do
  134.         say " "
  135.         signal getname
  136.     end  /* Do */
  137. end  /* Do */
  138. else
  139.  
  140. say " writing to  " outname
  141.  
  142. call lineout outname, "BBS use statistics for: " time(n) date(n)
  143. call lineout outname, " Total DOWNLOADS: # files=" totdownf ", #bytes=" totdownb
  144. call lineout outname, " Total UPLOADS:   # files="totupf ", #bytes=" totupb
  145. jusers=0
  146. do ll=1 to nth
  147.    parse var atime.ll a1 a2   /* date name */
  148.    if nowtime-a1> ddays then leave
  149.    jusers=jusers+1
  150. end /* do */
  151. call lineout outname, " # users (downloaders/uploaders) in the last " ddays " days =" jusers
  152.  
  153.  
  154.  
  155. call lineout outname, ""
  156. call lineout outname, " Top " topn " downloaders (files) : Top " topn " uploaders (files) "
  157. call lineout outname, " "
  158.  
  159. do ll=1 to topn
  160.    parse var adownf.ll a1 a2 ; b1=left(strip(a2),12) ; b2=left('('strip(a1)')',12)
  161.    parse var aupf.ll a1 a2 ; c1=left(strip(a2),12) ; c2=left('('strip(a1)')',12)
  162.    call lineout outname, b1 b2 '   : ' c1 c2
  163. end
  164. call lineout outname, " "
  165. call lineout outname, " Top " topn " downloaders (bytes) : Top " topn " uploaders (bytes) "
  166. do ll=1 to topn
  167.    parse var adownb.ll a1 a2 ; b1=left(strip(a2),12) ; b2=left('('strip(a1)')',12)
  168.    parse var aupb.ll a1 a2 ; c1=left(strip(a2),12) ; c2=left('('strip(a1)')',12)
  169.    call lineout outname, b1 b2 '   : ' c1 c2
  170. end
  171. call lineout outname, " "
  172. call lineout outname, " Top " topn " downloaders (file ratio) : Top " topn " uploaders (byte ratio) "
  173. do ll=1 to topn
  174.    parse var aratiof.ll a1 a2 ; a1=format(a1,,2);
  175.     b1=left(strip(a2),12) ; b2=left('('strip(a1)')',12)
  176.    parse var aratiob.ll a1 a2 ; a1=format(a1,,2)
  177.    c1=left(strip(a2),12) ; c2=left('('strip(a1)')',12)
  178.    call lineout outname, b1 b2 '   : ' c1 c2
  179. end
  180. call lineout outname, " "
  181. call lineout outname, " Most recent activity: "
  182. do ll=1 to topn
  183.    parse var atime.ll a1 a2
  184.     b1=left(strip(a2),12)
  185.    b2a=dateconv(trunc(a1),'B','N')
  186.    tmp=(a1-trunc(a1))*(24*60)
  187.    min=translate(format(tmp//60,2,0),'0',' ')
  188.    hr=tmp%60
  189.  
  190.    call lineout outname, b1 " : " b2a hr':'min
  191. end /* do */
  192.  
  193. call lineout outname
  194. say " Results saved to " outname
  195.  
  196.  
  197.  
  198.  
  199.  
  200. exit
  201.  
  202.  
  203.  
  204.   
  205.  /* ------------------------------------------------------------------ */
  206.  /* function: Check if ANSI is activated                               */
  207.  /*                                                                    */
  208.  /* call:     CheckAnsi                                                */
  209.  /*                                                                    */
  210.  /* where:    -                                                        */
  211.  /*                                                                    */
  212.  /* returns:  1 - ANSI support detected                                */
  213.  /*           0 - no ANSI support available                            */
  214.  /*          -1 - error detecting ansi                                 */
  215.  /*                                                                    */
  216.  /* note:     Tested with the German and the US version of OS/2 3.0    */
  217.  /*                                                                    */
  218.  /*                                                                    */
  219.  CheckAnsi: PROCEDURE
  220.    thisRC = -1
  221.  
  222.    trace off
  223.                          /* install a local error handler              */
  224.    SIGNAL ON ERROR Name InitAnsiEnd
  225.  
  226.    "@ANSI 2>NUL | rxqueue 2>NUL"
  227.  
  228.    thisRC = 0
  229.  
  230.    do while queued() <> 0
  231.      queueLine = lineIN( "QUEUE:" )
  232.      if pos( " on.", queueLine ) <> 0 | ,                       /* USA */
  233.         pos( " (ON).", queueLine ) <> 0 then                    /* GER */
  234.        thisRC = 1
  235.    end /* do while queued() <> 0 */
  236.  
  237.  InitAnsiEnd:
  238.  signal off error
  239.  RETURN thisRC
  240.  
  241.    
  242.  
  243. /*************/
  244. /* extract user header from userlog_lines. */
  245. get_user_header:procedure expose user_header.
  246. parse arg afile
  247. afile=strip(afile)
  248.  
  249. /* get header info. ; lines are ignored. User_header.0 contains list of
  250.    .extensions found (i.e.; user_header.!status, user_header.!privileges
  251.    yield user_header.0='STATUS PRIVILEGES '
  252. */
  253.  
  254. issht=1
  255. s1: nop
  256. if issht=1 then
  257.    oo=fileread(afile,userlog_lines,40)
  258. else
  259.    oo=fileread(afile,userlog_lines)
  260.  
  261. isdone=0
  262. user_header.0=' '
  263. do mm=1 to userlog_lines.0
  264.      aline=strip(userlog_lines.mm)
  265.      if abbrev(aline,';')=1 | aline=' ' then iterate
  266.      parse var aline atype ':' aval ; uatype=upper(strip(atype))
  267.      user_header.0=user_header.0||' '||uatype
  268.      if uatype='MESSAGES' then do 
  269.          isdone=1
  270.          leave
  271.      end  /* Do */
  272.      fo='!'||uatype
  273.      user_header.fo=aval
  274.      if uatype='STATUS' then userlog_lines.statusat=mm
  275.  end /* do */
  276.  if isdone=0  & issht=1 then do
  277.      drop user_header.
  278.      issht=0
  279.      signal s1
  280.  end
  281.  
  282.  return user_header.0
  283.  
  284.  
  285.  
  286.  
  287.  
  288.